# -*- coding: utf-8 -*-
# @Time    : 2019/10/25 16:22
# @Author  : xiao
import sys
import time
import unittest
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco

from basic.data import global_var, data
from basic.utils.getCaseReportXml import get_report
from basic.utils.initConfig import initConfig

class UIParent(unittest.TestCase):

    platform="Android"
    classCount=0

    def setUp(self):
        global_var._init()
        data.app_name(self.__str__())
        init_device(self.platform)
        # or use connect_device api
        # connect_device("Android:///")
        # install("path/to/your/apk")
        wake()
        start_app(global_var.get_value('app_name'))
        initConfig.init(self.platform)

    def tearDown(self):

        # 关掉app
        stop_app(global_var.get_value('app_name'))
        #清除app缓存
        # clear_app(self.appName)

    @staticmethod
    def caseResult(run, type):
        print("case nub:")
        nub=run.testsRun
        print(nub)
        print('seccess nub:')
        seccess=run.success_count
        print(seccess)
        result_list = run.result_list
        return get_report(result_list, nub, seccess, nub - seccess, type)



    @staticmethod
    def runCases(classNameList):
        className=""
        suite = unittest.TestSuite()
        for className in classNameList:
            suite.addTest(unittest.TestSuite(unittest.makeSuite(className)) )
        return suite









